//
//  TransferViewController.m
//  nonghubao
//
//  Created by Fenrir on 13-5-17.
//  Copyright (c) 2013年 Chongqing Nonghubao Co., Ltd. All rights reserved.
//

#import "TransferViewController.h"
#import "Helper.h"
#import "Config.h"
#import "JMFBase.h"
#import "RTLabel.h"
#import "TransferOpeningViewController.h"
#import "TransferInfoFormViewController.h"
#import "TransferApplyViewController.h"
#import "TransferNotEnoughViewController.h"
#import "StepOneViewController.h"


//  -业务逻辑细节说明-
//
//  @abstract       本类的业务逻辑重点是在根据用户是否开通转账业务的情况来呈现不同的view。

//  @discussion

//                  1、在viewDidAppear中，此时会向服务器请求用户的转账信息集，通过判断此信息集合是否存在转账信息来决断用户是否开通过转账业务。
//
//                      2.1、如果信息集为空，则用户未开通过转账业务，_transStatus = NO。那么此时设置温馨提示Label的内容，以及此时只有两个button，分别为“立即开通”和“以后再说”；
//                      2.2、如果信息集不为空，则用户开通了转账业务，_transStatus = YES。那么此时设置温馨提示Label的内容，以及此时有三个button，分别是“我要申请转账”、“修改银行信息”和“修改安全密码”；
//                      2.3、信息集不为空的时候，会马上向服务器请求用户是否存在未处理完成的转账，如果存在，那么就要以额外的view显示出上一笔转账的信息，并且当用户继续点击“我要申请转账”按钮时，只会弹出一个提示框；如果不存在，那么用户可以直接点击“我要申请转账”按钮进行转账业务的办理。


//  @notes          关于按钮集显示的判断：在viewDidLoad中，会将3个按钮都绘制好，等到逻辑判断完毕才addsubview到self.view中，状态改变时的button修改顺序为从下自上。
//                      当用户未开通转账业务时，底部的按钮为“以后再说”，中间的按钮为"立即开通"，顶部的按钮被隐藏；
//                      当用户开通了转账业务时，底部为“修改安全密码”，中间的按钮为“修改银行信息”，顶部的按钮为“我要申请转账”。
//                  用户点击了“我要申请转账”按钮时，客户端会做初步的金额和手续费的判断，如果用户账户余额小于TRANSFER_MIN_LIMIT + PROCEDURE_FEE的话，就要跳转到“余额不足”的页面去；
//                  否则跳转到申请转账页面


//  -类修改日志-
//  修改人   修改时间   针对版本   修改描述
//  

//最底部按钮的高度
#define BOTTOM_BUTTON_HEIGHT _SYS_FRAME_HEIGHT - 20.0f - 44.0f - 44.0f + 15.0f

@interface TransferViewController ()<UIAlertViewDelegate>

@end

@implementation TransferViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    UIButton *backButton = [Helper buttonWithStyle:ButtonStyleNavigationReturn];
    [backButton addTarget:self action:@selector(backButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    _scrollView = [[CustomScrollView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, _SYS_FRAME_HEIGHT)];
    _scrollView.backgroundColor = [UIColor whiteColor];
//    _scrollView.customDelegate = self;
    _scrollView.showsVerticalScrollIndicator = NO;
    _scrollView.showsHorizontalScrollIndicator = NO;
    CGSize newSize = CGSizeMake(self.view.frame.size.width, _SYS_FRAME_HEIGHT);
    
    [_scrollView setContentSize:newSize];
    [self.view addSubview:_scrollView];

    
//    //温馨提示
//    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(125.0f, 5.0f, 80.0f, 30.0f)];
//    titleLabel.font = _SYS_FONT_005;
//    titleLabel.text = _L(@"title_15");
//    [_scrollView addSubview:titleLabel];
//    
    //分割线或转账申请处理中提示
    _lineView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 0.5f)];
    
    _lineView.backgroundColor = [UIColor colorWithRed:245/255.0f green:245/255.0f blue:245/255.0f alpha:1.0f];
    
    _firstAdditionLabel = [[RTLabel alloc] initWithFrame:CGRectMake(30.0f, 20.0f, 300.0f, 25.0f)];
    _firstAdditionLabel.font = _SYS_FONT_005;
    _firstAdditionLabel.text = _L(@"tpl_30");
    _firstAdditionLabel.alpha = 0.0f;
    
    _secondAdditionLabel = [[RTLabel alloc] initWithFrame:CGRectMake(30.0f, _firstAdditionLabel.frame.origin.y + _firstAdditionLabel.frame.size.height, 300.0f, 25.0f)];
    _secondAdditionLabel.font = _SYS_FONT_005;
    _secondAdditionLabel.alpha = 0.0f;
    
    _thirdAdditionLabel = [[RTLabel alloc] initWithFrame:CGRectMake(30.0f, _secondAdditionLabel.frame.origin.y + _secondAdditionLabel.frame.size.height, 300.0f, 25.0f)];
    _thirdAdditionLabel.font = _SYS_FONT_005;
    _thirdAdditionLabel.alpha = 0.0f;
    
    //取消申请按钮
    _cancelButton = [[UIButton alloc] initWithFrame:CGRectMake(30.0f, _thirdAdditionLabel.frame.origin.y + _thirdAdditionLabel.frame.size.height+5.0f, 80.0f, 37.0f)];
    [_cancelButton setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"transaction_btn_005_n@2x" ofType:@"png"]] forState:UIControlStateNormal];
    [_cancelButton setTitle:@"取消申请" forState:UIControlStateNormal];    //取消申请
    [_cancelButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    _cancelButton.titleLabel.font = _SYS_FONT_004;
    _cancelButton.alpha = 0.0f;
    _cancelButton.tag = 5;
    [_cancelButton addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside];

    [_lineView addSubview:_firstAdditionLabel];
    [_lineView addSubview:_secondAdditionLabel];
    [_lineView addSubview:_thirdAdditionLabel];
    [_lineView addSubview:_cancelButton];
    
    [_scrollView addSubview:_lineView];
    
    //提示内容
    _contentLabel = [[RTLabel alloc] initWithFrame:CGRectMake(10.0f, _lineView.frame.origin.y + _lineView.frame.size.height + 5.0f, 300.0f, 10.0f)];
    [_contentLabel setFont:_SYS_FONT_005];
    
    _firstLabel = [[RTLabel alloc] initWithFrame:CGRectMake(10.0f, _contentLabel.frame.origin.y + _contentLabel.frame.size.height, 300.0f, 25.0f)];
    _firstLabel.font = _SYS_FONT_005;
    _firstLabel.text = [NSString stringWithFormat:_L(@"tpl_25"), TRANSFER_MIN_LIMIT];
    
    _secondLabel = [[RTLabel alloc] initWithFrame:CGRectMake(10.0f, _firstLabel.frame.origin.y + _firstLabel.frame.size.height, 300.0f, 25.0f)];
    _secondLabel.font = _SYS_FONT_005;
    _secondLabel.text = _L(@"tpl_26");
    
    _thirdLabel = [[RTLabel alloc] initWithFrame:CGRectMake(10.0f, _secondLabel.frame.origin.y + _secondLabel.frame.size.height, 300.0f, 38.0f)];
    _thirdLabel.font = _SYS_FONT_005;
    _thirdLabel.text = _L(@"tpl_27");
    
    //按钮集（编写顺序是从下自上）
    
    //按钮1
    _addtionalButton = [[UIButton alloc] initWithFrame:CGRectMake(10.0f, BOTTOM_BUTTON_HEIGHT, 300.0f, 44.0f)];
    [_addtionalButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _addtionalButton.titleLabel.font = _SYS_FONT_007;
    _addtionalButton.tag = 4;
    [_addtionalButton addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside];
    
    //按钮2
    _bottomButton = [[UIButton alloc] initWithFrame:CGRectMake(10.0f, BOTTOM_BUTTON_HEIGHT - 10.0f - 44.0f, 300.0f, 44.0f)];
    [_bottomButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _bottomButton.titleLabel.font = _SYS_FONT_007;
    _bottomButton.tag = 3;
    [_bottomButton addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside];
    
    //按钮3
    _middleButton = [[UIButton alloc] initWithFrame:CGRectMake(10.0f, BOTTOM_BUTTON_HEIGHT - 20.0f - 88.0f , 300.0f, 44.0f)];
    [_middleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _middleButton.titleLabel.font = _SYS_FONT_007;
    _middleButton.tag = 2;
    [_middleButton addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside];
    
    
    //按钮4  注：只用用户开通了转账服务才有顶部按钮，否则隐藏
    _topButton = [[UIButton alloc] initWithFrame:CGRectMake(10.0f, BOTTOM_BUTTON_HEIGHT - 30.0f - 132.0f, 300.0f, 44.0f)];
    [_topButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _topButton.titleLabel.font = _SYS_FONT_007;
    _topButton.tag = 1;
    [_topButton addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside];
 
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self transferInfoRequest];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 私有方法

/*!
 @abstract 向服务器请求用户的转账信息
 */
- (void)transferInfoRequest
{
    JSONRequest* request = [[JSONRequest alloc] initWithURLString:_JSON_URL_ACCOUNT_TRANSFER_INFO];
    request.hudOn = true;
    request.hudTitle = _L(@"title_loading_01");
    request.delegate = self;
    [request setSuccessSelector:@selector(transferDidReceived:)];
    [request asynchronous];
}

/*!
 @abstract 向服务器请求判断用户是否存在一笔转账在处理中
 */
- (void)transferApplyInfoRequest
{
    JSONRequest *request = [[JSONRequest alloc] initWithURLString:_JSON_URL_ACCOUNT_TRANSFER_APPLY_INFO];
    request.delegate = self;
    request.hudOn = true;
    request.hudTitle = _L(@"title_loading_01");
    [request asynchronous];
}

/*!
 @abstract 向服务器请求用户的账户信息
 */
- (void)accountInfoRequest
{
    JSONRequest *request = [[JSONRequest alloc] initWithURLString:_JSON_URL_ACCOUNT_GET_ACCOUNT];
    request.delegate = self;
    request.hudOn = true;
    request.hudTitle = _L(@"title_loading_01");
    [request setSuccessSelector:@selector(accountInfoDidReceived:)];
    [request asynchronous];
}

- (void)transferApplyCancelRequest
{
    JSONRequest *request = [[JSONRequest alloc] initWithURLString:_JSON_URL_ACCOUNT_TRANSFER_APPLY_CANCEL];
    request.delegate = self;
    request.hudOn = true;
    request.hudTitle = _L(@"title_loading_01");
    [request setSuccessSelector:@selector(transferApplyCancelRequestDidSuccess:)];
    [request asynchronous];
}

/*!
 @abstract 以动画的形式显示出上一笔转账的视图组件
 */
- (void)showAdditionView
{
    if (_lineView.frame.size.height > 0.5f) {
        return;
    }
    
    NSTimeInterval animationDuration = 0.5f;
    [UIView beginAnimations:@"show" context:nil];
    [UIView setAnimationDuration:animationDuration];
    CGSize newSize = CGSizeMake(self.view.frame.size.width, _SYS_FRAME_HEIGHT+145.0f);
    
    [_scrollView setContentSize:newSize];
    _lineView.frame = CGRectMake(0.0f, 0.0f, 320.0f, 145.0f);
    
    [self positioningViewsWithOffset:145.0f];
    
    _firstAdditionLabel.alpha = 1.0f;
    _secondAdditionLabel.alpha = 1.0f;
    _thirdAdditionLabel.alpha = 1.0f;
    _cancelButton.alpha = 1.0f;
    [UIView commitAnimations];
}

/*!
 @abstract 在用户不存在一笔转账正在处理中时，隐藏额外的view，并且重新更新view中组件的frame
 */
- (void)recoverView
{
    if (_lineView.frame.size.height == 0.5f) {
        return;
    }
    
    NSTimeInterval animationDuration = 0.5f;
    [UIView beginAnimations:@"show" context:nil];
    [UIView setAnimationDuration:animationDuration];
    
    CGSize newSize = CGSizeMake(self.view.frame.size.width, _SYS_FRAME_HEIGHT);
    
    [_scrollView setContentSize:newSize];
    _lineView.frame = CGRectMake(0.0f, 0.0f, 320.0f, 0.5f);
    _lineView.backgroundColor = [UIColor colorWithRed:245/255.0f green:245/255.0f blue:245/255.0f alpha:1.0f];
    
    [self positioningViewsWithOffset:-145.0f];
    
    _firstAdditionLabel.alpha = 0.0f;
    _secondAdditionLabel.alpha = 0.0f;
    _thirdAdditionLabel.alpha = 0.0f;
    _cancelButton.alpha = 0.0f;
    [UIView commitAnimations];

}

/*!
 @abstract _lineView在用户存在一笔转账信息未处理时，会变高，所以以它为参考的高度的view组件也要跟着变化frame。
 */
- (void)positioningViewsWithOffset:(CGFloat)offset
{
    _contentLabel.frame = CGRectMake(10.0f, _lineView.frame.origin.y + _lineView.frame.size.height + 5.0f, 300.0f, 10.0f);
    _firstLabel.frame = CGRectMake(10.0f, _contentLabel.frame.origin.y + _contentLabel.frame.size.height, 300.0f, 25.0f);
    _secondLabel.frame = CGRectMake(10.0f, _firstLabel.frame.origin.y + _firstLabel.frame.size.height, 300.0f, 25.0f);
    _thirdLabel.frame = CGRectMake(10.0f, _secondLabel.frame.origin.y + _secondLabel.frame.size.height, 300.0f, 38.0f);
    
    _addtionalButton.frame = CGRectMake(10.0f, _addtionalButton.frame.origin.y+offset, 300.0f, 44.0f);
    _bottomButton.frame = CGRectMake(10.0f, _bottomButton.frame.origin.y+offset, 300.0f, 44.0f);
    _middleButton.frame = CGRectMake(10.0f, _middleButton.frame.origin.y+offset , 300.0f, 44.0f);
    _topButton.frame = CGRectMake(10.0f, _topButton.frame.origin.y+offset, 300.0f, 44.0f);
}

#pragma mark - 自定义事件

- (void)backButtonEvent:(id)sender
{
    [self.navigationController dismissModalViewControllerAnimated:YES];
}

- (void)buttonEvent:(id)sender
{
    //按钮的tag业务判断也是从下自上的
    UIButton *clickedButton = (UIButton *)sender;
    
    if (_transStatus) {
        
        //在开通转账服务时，有一笔存在转账申请时，点击“取消申请”
        if (clickedButton.tag == 5) {
            [self transferApplyCancelRequest];
        }
        
        //在开通转账服务时，点击了找回安全密码按钮，跳转到找回安全密码页面
        else if (clickedButton.tag == 4) {
            
            StepOneViewController *stepOneVC = [[StepOneViewController alloc] init];
            UINavigationController *stepOneNC = [[UINavigationController alloc] initWithRootViewController:stepOneVC];
            [Helper navigationControllerCommonStyle:stepOneNC];
            
            [self.navigationController presentModalViewController:stepOneNC animated:YES];
            
            //设置需要处理找回安全密码的转账信息的id
            [[NSUserDefaults standardUserDefaults] setInteger:[_transferInfoArray[0][@"id"] integerValue] forKey:@"processId"];
        }
        
        //在开通转账服务时，点击了修改安全密码按钮，跳转到修改安全密码页面
        else if (clickedButton.tag == 3) {
            
            TransferInfoFormViewController *transferInfoFormVC = [[TransferInfoFormViewController alloc] initWithOption:clickedButton.tag];
            //取第一个转账信息
            transferInfoFormVC.transferInfo = [_transferInfoArray objectAtIndex:0];
            
            [transferInfoFormVC.navigationItem setTitle:_L(@"btn_modify_01")];
            
            UINavigationController *transferInfoFormNC = [[UINavigationController alloc] initWithRootViewController:transferInfoFormVC];
            [Helper navigationControllerCommonStyle:transferInfoFormNC];
            [self.navigationController presentModalViewController:transferInfoFormNC animated:YES];
            
        }
        //在开通转账服务时，点击了修改银行信息按钮，跳转到修改银行信息页面
        else if (clickedButton.tag == 2){
            
            TransferInfoFormViewController *transferInfoFormVC = [[TransferInfoFormViewController alloc] initWithOption:clickedButton.tag];
            
            
            //取第一个转账信息
            transferInfoFormVC.transferInfo = [_transferInfoArray objectAtIndex:0];
            [transferInfoFormVC.navigationItem setTitle:_L(@"btn_modify_02")];
            
            UINavigationController *transferInfoFormNC = [[UINavigationController alloc] initWithRootViewController:transferInfoFormVC];
            [Helper navigationControllerCommonStyle:transferInfoFormNC];
            [self.navigationController presentModalViewController:transferInfoFormNC animated:YES];
        }
        //在开通转账服务时，点击了我要申请转账按钮，先判断用户是否存在有上一次未处理完成的转账业务，如果存在（_transferPermisson=YES）那么弹出提示框，如果不存在（_transferPermisson=NO）那么就向服务器申请用户账户信息，并判断用户余额是否足够办理本次转账。
        else{
            
            
            if (_transferInfoArray && [_transferInfoArray[0][@"subbranch"] length] == 0) {
                
                UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:nil message:_L(@"alert_138") delegate:self cancelButtonTitle:_L(@"btn_yes_47") otherButtonTitles:nil];
                
                [alertView show];
                return;
            }
            
            if (_transferPermisson) {
                [Helper showAlertWithTitle:@"" andMessage:_L(@"alert_53")];
                return;
            }
            
            else{
                
                [self accountInfoRequest];
            }
            
        }
        
    }else{
        
        //在未开通转账服务时，点击了以后再说按钮，返回到账户信息页面
        if (clickedButton.tag == 3) {
            
            [self backButtonEvent:nil];
            
        }
        //在未开通转账服务时，点击了立即开通按钮，跳转到开通转账服务页面
        else if (clickedButton.tag == 2){
            
            TransferOpeningViewController *transferOpeningVC = [[TransferOpeningViewController alloc] init];
            
            [transferOpeningVC.navigationItem setTitle:_L(@"vc_title_064")];
            
            UINavigationController *transferOpeningNC = [[UINavigationController alloc] initWithRootViewController:transferOpeningVC];
            [Helper navigationControllerCommonStyle:transferOpeningNC];
            [self.navigationController presentModalViewController:transferOpeningNC animated:YES];
        }
        
    }
}

#pragma mark - JSONRequestDelegate

- (void)requestDidLoadJSON:(NSDictionary *)dict
{
    JMFBase* jmf = [[JMFBase alloc] initWithJSONDictionary:dict];
    
    if (jmf.status == JMStatusSucceed) {

        //data不为空，表示存在着上一笔转账业务未处理完，将上一笔转账信息以动画的形式显示出来
        if (jmf.data != nil) {            
            _secondAdditionLabel.text = [NSString stringWithFormat:_L(@"tpl_31"), [jmf.data objectForKey:@"createTime"]];
            _thirdAdditionLabel.text = [NSString stringWithFormat:_L(@"tpl_32"), [[jmf.data objectForKey:@"cash"] integerValue]];
            
            [self showAdditionView];
            _transferPermisson = YES;
            
        }
        
        //data为空，表示用户可以正常进行转账业务
        else{
            
//            [self recoverView];
            
            _transferPermisson = NO;
        }
        
    }
    else {
        [Helper easyShowJMFStatus:jmf];
    }
}

- (void)accountInfoDidReceived:(NSDictionary *)dict
{
    JMFBase* jmf = [[JMFBase alloc] initWithJSONDictionary:dict];
    
    if (jmf.status == JMStatusSucceed) {
        
        //当余额不足以转账时，跳转到余额不足的VC中
        if (TRANSFER_MIN_LIMIT + PROCEDURE_FEE > [[jmf.data objectForKey:@"balance"] floatValue]) {
            
            TransferNotEnoughViewController *transferNotEnoughVC = [[TransferNotEnoughViewController alloc] init];
            
            [transferNotEnoughVC.navigationItem setTitle:_L(@"vc_title_065")];
            
            UINavigationController *transferNotEnoughNC = [[UINavigationController alloc] initWithRootViewController:transferNotEnoughVC];
            [Helper navigationControllerCommonStyle:transferNotEnoughNC];
            [self.navigationController presentModalViewController:transferNotEnoughNC animated:YES];
        }
        
        //余额足，则跳到申请转账VC中
        else{
            
            TransferApplyViewController *transferApplyVC = [[TransferApplyViewController alloc] init];
            transferApplyVC.transferInfo = [_transferInfoArray objectAtIndex:0];
            transferApplyVC.balance = [[jmf.data objectForKey:@"balance"] floatValue];
            
            [transferApplyVC.navigationItem setTitle:_L(@"btn_apply_01")];
            
            UINavigationController *transferApplyNC = [[UINavigationController alloc] initWithRootViewController:transferApplyVC];
            [Helper navigationControllerCommonStyle:transferApplyNC];
            [self.navigationController presentModalViewController:transferApplyNC animated:YES];
        }

        
    }
    else {
        [Helper easyShowJMFStatus:jmf];
    }
}

- (void)transferDidReceived:(NSDictionary *)dict
{
    JMFBase* jmf = [[JMFBase alloc] initWithJSONDictionary:dict];
    
    if (jmf.status == JMStatusSucceed) {
        
        //如果获得的数据为空，那么表示用户未开通转账功能
        if (jmf.data.count == 0) {
            
            _transStatus = NO;
            
            _lineView.backgroundColor = [UIColor colorWithRed:239/255.0f green:239/255.0f blue:239/255.0f alpha:1.0f];
            [_contentLabel setText:_L(@"tpl_22")];
            _contentLabel.frame = CGRectMake(_contentLabel.frame.origin.x, _contentLabel.frame.origin.y, _contentLabel.frame.size.width, 100);
            [_bottomButton setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"com_btn_008_n@2x" ofType:@"png"]] forState:UIControlStateNormal];
            [_bottomButton setTitle:_L(@"btn_back_02") forState:UIControlStateNormal];    //以后再说
            
            [_middleButton setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"com_btn_006_n@2x" ofType:@"png"]] forState:UIControlStateNormal];
            [_middleButton setTitle:_L(@"btn_open_01") forState:UIControlStateNormal];    //立即开通
            
            _topButton.hidden = YES;
            
        }
        
        else{
            
            _transStatus = YES;
            
            //已开通情况下，_contentLabel不显示文字
            [_contentLabel setText:@""];
            
            //在请求完成后，确定了文字的显示方式时，才将各个组件添加到self.view中，以免给用户一种切换过view的效果
            [_scrollView addSubview:_firstLabel];
            [_scrollView addSubview:_secondLabel];
            [_scrollView addSubview:_thirdLabel];
            
            [_addtionalButton setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"com_btn_028_n@2x" ofType:@"png"]] forState:UIControlStateNormal];
            [_addtionalButton setTitle:@"找回安全密码" forState:UIControlStateNormal];    //找回安全密码
            
            [_bottomButton setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"com_btn_007_n@2x" ofType:@"png"]] forState:UIControlStateNormal];
            [_bottomButton setTitle:_L(@"btn_modify_01") forState:UIControlStateNormal];    //修改安全密码
            
            [_middleButton setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"com_btn_008_n@2x" ofType:@"png"]] forState:UIControlStateNormal];
            [_middleButton setTitle:_L(@"btn_modify_02") forState:UIControlStateNormal];    //修改银行信息
            
            _topButton.hidden = NO;
            [_topButton setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"com_btn_006_n@2x" ofType:@"png"]] forState:UIControlStateNormal];
            [_topButton setTitle:_L(@"btn_apply_01") forState:UIControlStateNormal];    //我要申请转账
            
            //当转账信息不为空时，就获取它，直接传递到修改银行信息页面
            //暂时只有一条转账信息，以后会像地址管理一样，管理多条转账信息。
            _transferInfoArray = [dict objectForKey:@"data"];
            
            //判断用户是否存在一笔转账在处理中
            [self transferApplyInfoRequest];
        }
        
        //在请求完成后，确定了文字和按钮的显示方式时，才将各个组件添加到self.view中，以免给用户一种切换过view的效果
        [_scrollView addSubview:_contentLabel];
        [_scrollView addSubview:_addtionalButton];
        [_scrollView addSubview:_bottomButton];
        [_scrollView addSubview:_middleButton];
        [_scrollView addSubview:_topButton];
        
    }
    else {
        [Helper easyShowJMFStatus:jmf];
    }
}

- (void)transferApplyCancelRequestDidSuccess:(NSDictionary *)dict
{
    JMFBase* jmf = [[JMFBase alloc] initWithJSONDictionary:dict];
    if (jmf.status == JMStatusSucceed) {
        [self recoverView];
    }
    [Helper easyShowJMFStatus:jmf];
}
//
- (void)requestFailWithNetworkUnavailabe
{
    [Helper showAlertWithTitle:nil andMessage:_L(@"title_networkunavailabe")];
}

#pragma mark - UIAlertView Delegate

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    TransferInfoFormViewController *transferInfoFormVC = [[TransferInfoFormViewController alloc] initWithOption:2];
    
    
    //取第一个转账信息
    transferInfoFormVC.transferInfo = [_transferInfoArray objectAtIndex:0];
    [transferInfoFormVC.navigationItem setTitle:_L(@"btn_modify_02")];
    
    UINavigationController *transferInfoFormNC = [[UINavigationController alloc] initWithRootViewController:transferInfoFormVC];
    [Helper navigationControllerCommonStyle:transferInfoFormNC];
    [self.navigationController presentModalViewController:transferInfoFormNC animated:YES];
}
@end
